#!/bin/sh
# sparse shell script interpreter
# usage: sssi <input file> <output file>
#
readSssCommand() {
	echo -n  > "${tmp}"
	while read line
	do
		if test "X${line}" = "X#SPARSE_SHELL_SCRIPT_EXECUTE_END"
		then
			break
		else
				echo "${line}" >> "${tmp}"
		fi
	done
}

if test $# != 2
then
	echo "usage: sssi <input file> <output file>"
fi
input="$1"
output="$2"
tmp=/tmp/sssitmpscript
rm -f "${output}"
cat "${input}" | while read line
do
	if test "X${line}" = "X#SPARSE_SHELL_SCRIPT_EXECUTE"
	then
		readSssCommand
		. "${tmp}"
	elif test "X${line}" = "X#SPARSE_SHELL_SCRIPT_EXECUTE_AND_INCLUDE_STDOUT"
	then
		readSssCommand
		. "${tmp}" >> "${output}"
	else
		echo "${line}" >> "${output}"
	fi
done
rm -f "${tmp}"
